<?php
if (!defined('sugarEntry')) {
    session_start();
    session_destroy();
    header("Location: ../iphone.php");
}
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004 - 2007 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road, 
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
*
* In accordance with Section 7(b) of the GNU General Public License version 3, 
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
/*********************************************************************************
* Function:    sugar-iphone-client for SugarCRM
* Description: Header lines used on each page of the ThinClient
* Author:      Editha Kuske - 2008, Richard John Jensen 2009
* Revision:      $Id: header.php 6 2009-12-26 16:59:05Z richardjohnjensen $
********************************************************************************/
session_start();

require_once('sugar-iphone-client/config.php');
require_once('sugar-iphone-client/meta_array.php');
require_once('sugar-iphone-client/db_soap.php');
require_once('sugar-iphone-client/functions.php');

// --------- Global Vars ----------
$login_failed = "";

// --------- Thin Soap Client ----------
$sugar_soap_client = new Sugar_SOAP_Client();
$sugar_soap_client->initialize();

// --------- Login ----------
if (isset($_POST['btn_login'])) {
    $login_failed = do_login();
}

// --------- Assigned User ----------
$modus = get_par('modus');
if ($modus == "") {
    $modus ="all";
}
$_SESSION['modus'] = $modus;
if ($modus == "all") {
    $_SESSION['only_my_items'] = "1";
    unset($_SESSION['main_bean']);
    unset($_SESSION['location']);
    $_SESSION['start_pos'] = 0;
    $_SESSION['search'] = "";
}
// --------- Assigned User ----------
if (isset($_POST['sel_users'])) {
    $sel_users = $_POST['sel_users'];
} else if (isset($_SESSION['sel_users'])) {
    $sel_users = $_SESSION['sel_users'];
} else {
    $sel_users = $_SESSION['authenticated_user_id'];
}

$_SESSION['sel_users'] = $sel_users;

// ---------Bean in Detailmask-----------
if (isset($_GET['bean'])) {
    $bean = $_GET['bean'];
    $ar_bean_descr = $ar_beans[$bean];
}
if (isset($_GET['bean_id'])) {
    $bean_id = $_GET['bean_id'];
} else {
    $bean_id = "0";
}

//---------- list_bean -------------
if (isset($_GET['list_bean'])) {
    $list_bean = $_GET['list_bean'];
}

// --------------------
if (isset($_SESSION['session_id'])) {
    $session_id = $_SESSION['session_id'];
} else {
    $session_id = "0";
}

// --------------------
if (isset($_POST['btn_logout'])) {
    do_logout("btn_logout");
}

// --------------- Go Back Path -------------------
$str_location = get_location_par();
if (!isset($_SESSION['location'])) {
    $_SESSION['location'][0] = $str_location;
} else {
    $last_pos = count($_SESSION['location'])-1;
    $last_location =  $_SESSION['location'][$last_pos];
    if ($last_location != $str_location) {
		$html = <<<__BLOCK__
		<hr>last_location=$last_location<br>str_location=$str_location<br>
__BLOCK__;
		//echo $html;
        $attach = 1;
        if ($last_pos > 0) {
            $pos_before = $last_pos -1;
            if ($_SESSION['location'][$pos_before] == $str_location) {
                unset($_SESSION['location'][$last_pos]);
                $attach = 0;
            } else if (isset($_GET['action'])) {
                if ($_GET['action'] == 'select') {
                    // Add Invitees to related Call / Meeting
                    $attach = 0;
                }
            }
            
        }
        if ($attach) {
            $last_pos++;
            $_SESSION['location'][$last_pos] = $str_location;
        }
    }
}
$go_back = "";
if (!empty($_SESSION['location'])) {
    $pos = count($_SESSION['location'])-1;
    if ($pos > 0) {
        $pos--;
        $go_back_params = $_SESSION['location'][$pos];
        $go_back = '<a href="iphone.php?' . $go_back_params . '"><img src="sugar-iphone-client/images/go_back.gif" alt="go back" /></a>';
    }
}

?>